﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Student
{
    class StundentTest
    {
        static void Main(string[] args)
        {
            List<int> marks = new List<int>();
            marks.Add(2);
            marks.Add(6);
            List<int> otherMark = new List<int>();
            otherMark.Add(2);
            otherMark.Add(2);
            Group math = new Group (2,"math");
            Group shano = new Group(5,"shano");
            Student pesho = new Student("pesho", "gosho", "121206006", "022361630", "starbreaker@abv.bg", marks, math,2);
            Student gosho = new Student("gosho", "pesho", "121208006", "+359-22361630", "starbreaker@abv.bg", otherMark, shano,5);
            Student pesho1 = new Student("pesh", "gosho1", "121208006", "0887361630", "starbreaker@gbg.bg", marks, math,2);
            List<Student> students = new List<Student>();
            students.Add(pesho);
            students.Add(gosho);
            students.Add(pesho1);
            var groups = new[]
            {
                new Group (2,"math"),
                new Group(5,"shano")
            };

            string[] strings = 
            {
                "a",
                "daw",
                "dawdawdwad",
                "dawd"
            };

            //Ex1
            //var subset = from stud in students where stud.GroupNumber == 2 orderby stud.FirstName select stud;

            //Ex2
            //var subset = students.Where(stud => stud.GroupNumber == 2).OrderBy(stud => stud.FirstName);

            //Ex3
            //var subset = students.Where(stud => stud.Email.EndsWith("abv.bg"));

            //Ex4
            //string pattern = @"\A02[0-9]{7}\Z|\A\+359-2[0-9]{7}\Z";
            //Regex matcher = new Regex(pattern);
            //var subset = students.Where(stud => matcher.IsMatch(stud.Tel));

            //Ex5
            //var subset = from stud in students
            //             where stud.Marks.Contains(6)
            //             select new {FullName = stud.FirstName+" "+stud.LastName, Marks = stud.Marks};

            //Ex6
            //var subset = students.Where(stud => stud.Marks.Count(mark => mark == 2) == 2);

            //Ex7
            //string pattern = @"\A[0-9]{4}06[0-9]{3}\Z";
            //Regex matcher = new Regex(pattern);
            //var subset = students.Where(stud => matcher.IsMatch(stud.PFN));

            //Ex8
            //var subset = from hlape in students
            //             join g in groups
            //             on hlape.GroupNumber equals g.PGroupNumber
            //             where g.PGroupNumber == 5
            //             select hlape;


            //Ex9 
            //var longestString = from str in strings
            //                    orderby str.Length descending
            //                    select str;

            //Console.WriteLine("{0}",longestString.ElementAt<string>(0));


            //Ex10
            //var subset = from stud in students
            //             group stud by stud.Group.DepartmentName;


            //Ex11
            var subset = students.GroupBy(stud => stud.Group.DepartmentName);

            foreach (var item in subset)
            {
                Console.WriteLine(item.Key);
                foreach (var student in item) 
                {
                    Console.WriteLine("{0} {1}",student.FirstName,student.LastName);
                }
            }
        }
    }
}
